package com.action;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.dao.AdminFactory;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
	private String Type;
	private String username;
	private String password;
	private String msg;

	public String getType() {
		return Type;
	}

	public void setType(String type) {
		Type = type;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String execute() throws Exception {
		if (Type.equals("系统管理员")) {
			if (AdminFactory.getIAdminDaoInstance().checkLogin(username, password) == null) {
				msg = "用户名或密码错误！！";
				return INPUT;
			} else {
				String name = AdminFactory.getIAdminDaoInstance().checkLogin(username, password);
				HttpSession session = ServletActionContext.getRequest().getSession();
				session.setAttribute("name", name);
				session.setAttribute("type", "1");
				return SUCCESS;
			}
		} else {
			msg = "用户名或密码错误！！";
			return INPUT;
		}
	}
}